package io.adrainty.bolee.security.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.adrainty.bolee.framework.commons.basic.ResultDTO;
import io.adrainty.bolee.framework.commons.basic.TreeDTO;
import io.adrainty.bolee.framework.commons.utils.ResultDTOUtil;
import io.adrainty.bolee.security.models.entity.DeptEntity;
import io.adrainty.bolee.security.service.IDeptService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>DeptController</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description DeptController
 * @since 2025/8/7 13:49:08
 */

@Tag(name = "部门管理接口")
@RestController
@RequestMapping("/dept")
public class DeptController {

    @Resource
    private IDeptService deptService;

    @PostMapping("/page/{pageNum}/{pageSize}")
    @Operation(summary = "获取部门分页")
    public ResultDTO<IPage<DeptEntity>> pageDept(@RequestBody DeptEntity deptEntity,
                                                 @PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize) {
        IPage<DeptEntity> result = deptService.pageDept(pageNum, pageSize, deptEntity);
        return ResultDTOUtil.success(result);
    }

    @PutMapping
    @Operation(summary = "创建部门")
    public ResultDTO<DeptEntity> createDept(@RequestBody DeptEntity deptEntity) {
        DeptEntity result = deptService.createDept(deptEntity);
        return ResultDTOUtil.success(result);
    }

    @PatchMapping
    @Operation(summary = "部门修改")
    public ResultDTO<Boolean> updateDept(@RequestBody DeptEntity entity) {
        Boolean result = deptService.updateDept(entity);
        return ResultDTOUtil.success(result);
    }

    @PostMapping("/list")
    @Operation(summary = "获取部门列表")
    public ResultDTO<List<DeptEntity>> findDeptList(@RequestBody DeptEntity entity) {
        List<DeptEntity> result = deptService.findDeptList(entity);
        return ResultDTOUtil.success(result);
    }

    @PostMapping("/tree")
    @Operation(summary = "获取部门树")
    public ResultDTO<TreeDTO> findDeptTree(@RequestBody DeptEntity entity) {
        TreeDTO result = deptService.findDeptTree(entity);
        return ResultDTOUtil.success(result);
    }

}
